function viewUser(){
   getData('User');
}

function viewBook(){
   getData('Book');
}

function checkBoxNum(objName){
   var ids=document.getElementsByName(objName);
   var chkNum=0;
   for(var i=0;i<ids.length;i++){
      if(ids[i].checked){
         chkNum+=1;
      }
   }
   return chkNum;
}

function exit(){
   window.location.href=requestContextPath+'/info/login_exit.do';
}

function addUser(){
   window.location.href=requestContextPath+'/info/user_editUser.do';
}

function editUser(){
   var ids=document.getElementsByName('id');
   var chkNum=checkBoxNum('id');
   if(chkNum==1){
      for(var i=0;i<ids.length;i++){
      if(ids[i].checked){
         var url=requestContextPath+'/info/user_editUser.do?id='+ids[i].value;
         window.location.href=url;
      } 
      }
   }else{
      alert('请选中一条记录进行编辑！');
      return
   }
   
}

function delUser(){
   var ids=document.getElementsByName('id');
   var chkNum=checkBoxNum('id');
   if(chkNum>0){
      if(confirm('确定删除选中记录?')){
      var idStr='';
      for(var i=0;i<ids.length;i++){
         if(ids[i].checked){
            idStr=idStr+ids[i].value+',';
         }
      }
      var url=requestContextPath+'/info/user_delUser.do?idStr='+idStr;
      window.location.href=url;
      }else{
      return
      }
   }else{
      alert('请选中要删除的记录!');
      return
   }
}

function addBook(){
   window.location.href=requestContextPath+'/info/book_editBook.do';
}

function editBook(){
   var ids=document.getElementsByName('id');
   var chkNum=checkBoxNum('id');
   if(chkNum==1){
      for(var i=0;i<ids.length;i++){
      if(ids[i].checked){
         var url=requestContextPath+'/info/book_editBook.do?id='+ids[i].value;
         window.location.href=url;
      } 
      }
   }else{
      alert('请选中一条记录进行编辑！');
      return
   }
}

function delBook(){
   var ids=document.getElementsByName('id');
   var chkNum=checkBoxNum('id');
   if(chkNum>0){
      if(confirm('确定删除选中记录?')){
      var idStr='';
      for(var i=0;i<ids.length;i++){
         if(ids[i].checked){
            idStr=idStr+ids[i].value+',';
         }
      }
      var url=requestContextPath+'/info/book_delBook.do?idStr='+idStr;
      window.location.href=url;
      }else{
      return
      }
   }else{
      alert('请选中要删除的记录!');
      return
   }
}

function lendBook(){
   var ids=document.getElementsByName('id');
   var userId=document.getElementById('lendTo').value;
   var chkNum=checkBoxNum('id');
   if(chkNum>0){
      if(confirm('借出所选书籍?')){
      var idStr='';
      for(var i=0;i<ids.length;i++){
         if(ids[i].checked){
            var tr=ids[i].parentNode.parentNode;
            var obj=tr.children['5'].innerText;
            if(obj=='在库'){
               idStr=idStr+ids[i].value+',';
            }else{
               alert('无法借阅'+tr.children['2'].innerText)
               return
            }
         }
      }
      var url=requestContextPath+'/info/login_lendBook.do?userId='+userId+'&idStr='+idStr;
      window.location.href=url;
      }else{
      return
      }
   }else{
      alert('请选择要借出的书籍!');
      return
   }
}

function retuBook(){
   var ids=document.getElementsByName('id');
   var chkNum=checkBoxNum('id');
   if(chkNum>0){
      if(confirm('归还所选书籍?')){
      var idStr='';
      for(var i=0;i<ids.length;i++){
         if(ids[i].checked){
            var tr=ids[i].parentNode.parentNode;
            var obj=tr.children['5'].innerText;
            if(obj=='借出'){
               idStr=idStr+ids[i].value+',';
            }else{
               alert(tr.children['2'].innerText+'目前在库!')
               return
            }
         }
      }
      var url=requestContextPath+'/info/login_retuBook.do?idStr='+idStr;
      window.location.href=url;
      }else{
      return
      }
   }else{
      alert('请选择要归还的书籍!');
      return
   }
}